<template>
    <div>
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>添加用户</span>
<!--                <el-button style="float: right; padding: 3px 0" type="text">添加</el-button>-->
            </div>
            <div class="text item">
                <el-form :label-position="labelPosition" ref="ruleForm" label-width="80px"
                         :model="formLabelAlign" >

                    <el-form-item label="用户名" prop="uname">
                        <el-input  v-model="formLabelAlign.uname"></el-input>
                    </el-form-item>
                    <el-form-item label="密码" prop="upass">
                        <el-input v-model="formLabelAlign.upass"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click.native.prevent="addusers" >添加</el-button>
                        <el-button @click="resetForm">重置</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
    </div>
</template>

<script>
    import {AddUser} from "../../network/admin";

    export default {
        name: "Adduser",
        data(){
            return{
                labelPosition: 'right',
                formLabelAlign: {
                    uname: '',
                    upass: '',
                },

            }
        },
        methods:{
            resetForm() {
                this.$refs.ruleForm.resetFields();
            },
            addusers(){
                AddUser(Object.assign(this.formLabelAlign,this.$store.state.auths)).then(res => {
                    if (res.code === 1) {
                        this.$message({
                            message: '添加成功',
                            type: 'success'
                        });
                    }else if (res.code === -1){
                        this.$message.error('用户已存在');
                    }else {
                        this.$message.error('失败');
                    }
                })
            }
        }
    }
</script>

<style scoped>
    .text {
        font-size: 14px;
    }

    .item {
        margin-bottom: 18px;
        width: 30vw;
    }

    .clearfix:before,
    .clearfix:after {
        display: table;
        content: "";
    }
    .clearfix:after {
        clear: both
    }

    .box-card {
        width: 100%;
        height: 85vh;
    }
</style>
